package cn.wolfcode.crm.Service.impl;

import cn.wolfcode.crm.Service.ICustomerTransferService;
import cn.wolfcode.crm.domain.CustomerTransfer;
import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.mapper.CustomerTransferMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.util.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CustomerTransferServiceImpl implements ICustomerTransferService {
    @Autowired
    private CustomerTransferMapper customerTransferMapper;


    @Override
    public void insert(CustomerTransfer record) {
        //获取员工对象  代码抽取到UserContext类中
        Employee currentEmp = UserContext.getEmployee();
        record.setOperator(currentEmp);//操作人
        record.setOperateTime(new Date());//操作时间
        customerTransferMapper.insert(record);
    }

    @Override
    public void updateByPrimaryKey(CustomerTransfer record) {
        customerTransferMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageInfo<CustomerTransfer> queryForList(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<CustomerTransfer> list = customerTransferMapper.queryForList(qo);

        return new PageInfo<>(list);
    }
}
